﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using AssetManageSystem.Model.AssetManage;
using AssetManageSystem.Model;
using AssetManageSystem.Model.Enum;
using AssetManageSystem.ViewModel.AssetManage.AssetInfoVMs;


namespace AssetManageSystem.ViewModel.AssetManage.AssetBorrowVMs
{
    public partial class AssetBorrowVM : BaseCRUDVM<AssetBorrow>
    {
        public List<ComboSelectListItem> AllAssetIds { get; set; }
        public AssetInfoListVM AssetInfoList { get; set; }

        public AssetBorrowVM()
        {
            //SetInclude(x => x.AssetId);
        }

        protected override void InitVM()
        {
            AssetInfoList = Wtm.CreateVM<AssetInfoListVM>();
            AssetInfoList.SearcherMode = ListVMSearchModeEnum.MasterDetail;

            Entity.DocNumber = "BR" + Helper.RandomNumber.GetRandom();
        }

        public override void DoAdd()
        {
            //修改资产的status的值
            var Infos = DC.Set<AssetInfo>().Where(x => x.ID == Entity.AssetId).Select(x => x).ToList().FirstOrDefault();
            if (Infos != null)
            {
                Infos.Status = AsStatusEnum.Borrow;
                DC.SaveChanges();
            }
            base.DoAdd();
        }

        public override void DoEdit(bool updateAllFields = false)
        {
            base.DoEdit(updateAllFields);
        }

        public override void DoDelete()
        {
            base.DoDelete();
        }
    }
}
